#ifndef _KTV_WINDOW_H_
#define _KTV_WINDOW_H_

#include "ui_rect.h"
#include "ui_color.h"
#include "ui_error.h"
#include "ui_message_client.h"
#include <string>
#include <list>
#include <typeinfo>
#include "SDL/SDL.h"
using namespace std;

namespace UI
{

class UI_View;

class UI_Window : public UI_MessageClient
{
public:
	UI_Window(const UI_Rect& WindowRect, UI_Window* pParent);
	virtual ~UI_Window(void);
	virtual std::string GetClassName(void) const { return typeid(*this).name(); }
	virtual void SetWindowRect(const UI_Rect& WindowRect);
	virtual UI_Rect GetWindowRect(void) const { return m_WindowRect; }
	virtual void MoveWindow(const UI_Point& MoveDistance);
	virtual UI_Rect GetClientRect(void) const { return m_ClientRect; }
	enum EAncestor {
		PARENT, //!< return the direct parent of the window
		ROOT //!< climb the parent chain all the way until the root and return it
	};
	virtual UI_Window* GetAncestor(EAncestor eAncestor) const;
	virtual std::list<UI_Window*> GetChildWindows(void) const { return m_ChildWindows; }
	virtual bool IsChildOf(UI_Window* pWindow) const;
	virtual bool IsVisible(void) { return m_bVisible; }
	virtual void SetVisible(bool bVisible);
	virtual SDL_Surface* GetSDLSurface(void) { return m_pSDLSurface; }
	virtual UI_Rect ClientToView(const UI_Rect& Rect) const;
	virtual UI_Point ClientToView(const UI_Point& Point) const;
	virtual UI_Rect ViewToClient(const UI_Rect& Rect) const;
	virtual UI_Point ViewToClient(const UI_Point& Point) const;
	virtual UI_Rect ViewToWindow(const UI_Rect& Rect) const;
	virtual UI_Point ViewToWindow(const UI_Point& Point) const;
	virtual bool HitTest(const UI_Point& Point) const;
	virtual void Draw(void);
	virtual void PaintToSurface(SDL_Surface* ScreenSurface, const UI_Point& Offset);
	virtual void SetNewParent(UI_Window* pNewParent,bool revEvent = true);
	virtual bool OnMouseButtonDown(UI_Point Point, unsigned int Button);
	virtual bool OnMouseButtonUp(UI_Point Point, unsigned int Button);
	virtual bool HandleMessage(UI_Message* pMessage);
	virtual bool IfReceiveEvent(void) const { return m_receive_event; }

protected:
	virtual void RegisterChildWindow(UI_Window* pWindow);
	virtual void DeregisterChildWindow(UI_Window* pWindow);
	UI_Rect m_WindowRect;
	UI_Rect m_ClientRect;
	UI_Window* m_pParentWindow;
	std::list<UI_Window*> m_ChildWindows;
	SDL_Surface* m_pSDLSurface;
	bool m_bVisible;
	bool m_receive_event;
private:
	void operator=(UI_Window) { }
};

}

#endif

